package com.weilan.ark3.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.weilan.ark3.service.ExcelFaultService;
import com.weilan.ark3.sqlite.SqlUtil;
import com.weilan.ark3.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

@RestController
@CrossOrigin
public class ExcelFaultController {
    @Value("${excel.outPut2}")
    private  String excelOutPutPath;
    @Autowired
    private  ExcelFaultService excelFaultService;
    //    @ApiOperation(value = "导出Excel")
//    @PostMapping("/bbb")
//    public  void dataToExcel(@RequestBody ModuleSearchBo moduleSearchBo) {
    public void dataToExcel(String tbName) {
        StringBuffer sqlScript = new StringBuffer();
        sqlScript.append(".headers on\n" + ".mode csv\n"+ ".output ");
        sqlScript.append(MessageFormat.format("{0}/{1}{2}.csv",
                excelOutPutPath,
                DateUtils.currentTimeNamingFile(),
                tbName)+"\n");
        String sqlStr = SqlUtil.generateFaultSql(tbName);
        sqlScript.append(sqlStr);
        SqlUtil.createScript(sqlScript.toString(),excelOutPutPath);
    }

}
